<?php

/**
 * This is the model class for table "{{biometry}}".
 *
 * The followings are the available columns in table '{{biometry}}':
 * @property string $id
 * @property string $category_id
 * @property double $length
 * @property double $weight
 * @property string $sex
 * @property string $maturity_stage_id
 * @property string $create_time
 * @property string $create_user_id
 * @property string $update_time
 * @property string $update_user_id
 *
 * The followings are the available model relations:
 * @property MaturityStage $maturityStage
 * @property Category $category
 */
class Biometry extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Biometry the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{biometry}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('category_id, length, weight, sex, maturity_stage_id, create_time, create_user_id, update_time, update_user_id', 'required'),
			array('length, weight', 'numerical'),
			array('category_id, maturity_stage_id, create_user_id, update_user_id', 'length', 'max'=>10),
			array('sex', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, category_id, length, weight, sex, maturity_stage_id, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'maturityStage' => array(self::BELONGS_TO, 'MaturityStage', 'maturity_stage_id'),
			'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'category_id' => 'Category',
			'length' => 'Length',
			'weight' => 'Weight',
			'sex' => 'Sex',
			'maturity_stage_id' => 'Maturity Stage',
			'create_time' => 'Create Time',
			'create_user_id' => 'Create User',
			'update_time' => 'Update Time',
			'update_user_id' => 'Update User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('category_id',$this->category_id,true);
		$criteria->compare('length',$this->length);
		$criteria->compare('weight',$this->weight);
		$criteria->compare('sex',$this->sex,true);
		$criteria->compare('maturity_stage_id',$this->maturity_stage_id,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user_id',$this->create_user_id,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user_id',$this->update_user_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}